<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    <title>index首页</title>
    <style>
      html, body {
        margin: 0;
        padding: 0;
        height: 100%;
        background: linear-gradient(to bottom right, red, gold);
      }
      .box {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 400px;
        height: 250px;
        background-color: rgba(255, 255, 255, .6);
        margin: 100px auto 0;
        border-radius: 10px;
        box-shadow: 10px 10px 10px rgba(0, 0, 0, .5);
      }
      .box > div {
        font-size: 62px;
      }
    </style>
  </head>
  <body>
    <div class="box">
      <div id="HH">00</div>
      <div>:</div>
      <div id="mm">00</div>
      <div>:</div>
      <div id="ss">00</div>
    </div>

    <script type="text/javascript">
      window.onload = function () {
        // 定时器 每隔一秒执行一次
        setInterval(() => {
          
          let date = new Date()
          let HH = date.getHours()
          let mm = date.getMinutes()
          let ss = date.getSeconds()

          // 为页面上的元素赋值
          let H = document.querySelector('#HH');
          H.innerHTML = HH < 10 ? '0' + HH : HH;
          let m = document.querySelector('#mm');
          m.innerHTML = mm < 10 ? '0' + mm : mm;
          let s = document.querySelector('#ss');
          s.innerHTML = ss < 10 ? '0' + ss : ss;


        }, 1000);
      }
    </script>
  </body>
</html>